package com.totoro.transfer;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.springframework.util.StringUtils;

import java.io.*;
import java.util.HashMap;
import java.util.Map;

public class TJson20180403 {

    public static void transfer() {

        String url = "/Users/swy/Library/Containers/com.tencent.xinWeChat/Data/Library/Application Support/com.tencent.xinWeChat/2.0b4.0.9/bd63c81b829ccfbd21d0b7bc3439ae70/Message/MessageTemp/bcbcdef8667f3a03fe425acd86ba0994/File";
        String dir = "/Users/swy/Library/Containers/com.tencent.xinWeChat/Data/Library/Application Support/com.tencent.xinWeChat/2.0b4.0.9/bd63c81b829ccfbd21d0b7bc3439ae70/Message/MessageTemp/b57159745b91a3500b5571651c6ad49f/File";
        //图片
        Map<String, String> cache1 = new HashMap();
        Map<String, String> cache2 = new HashMap();
        try {
            BufferedReader readerCvs = new BufferedReader(new FileReader(new File(url + "/属性判断最终版.txt")));
            String line1 = null;
            while ((line1 = readerCvs.readLine()) != null) {
                if (!StringUtils.isEmpty(line1.split(",")[0])) {
                    cache1.put(line1.split(",")[0], line1.split(",")[1].trim());
                }

            }
            readerCvs.close();

            BufferedReader reader2 = new BufferedReader(new FileReader(new File(dir + "/英文标签")));
            String line2 = null;
            while ((line2 = reader2.readLine()) != null) {
                if (!StringUtils.isEmpty(line2.split(",")[0])) {
                    cache2.put(line2.split(",")[0].trim(), line2.split(",")[1]);
                }
            }
            reader2.close();


            File dirFile = new File("/Users/swy/Documents/transfer/card1.json");
            BufferedWriter writer = new BufferedWriter(new FileWriter(dirFile));

            System.out.println(String.format("开始处理文件..."));
            JSONArray result = new JSONArray();
            int i = 0;
            for (Map.Entry<String, String> entry : cache1.entrySet()) {
                JSONObject temp = new JSONObject();
                if (!entry.getValue().trim().contains("无法判断")
                        && cache2.containsKey(entry.getValue().trim())
                        ) {
                    System.out.println(i++ + "///" + entry.getKey() + "///" + entry.getValue() + "///" + cache2.get(entry.getValue().trim()));
                    temp.put(entry.getKey(), cache2.get(entry.getValue().trim()));
                    result.add(temp);
                }
            }
            writer.write(result.toJSONString());
            System.out.println(result.toJSONString());
            writer.flush();
            writer.close();

        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public static void main(String[] args) {
        transfer();
    }
}
